#coding=utf-8
import xmlrpclib
from SimpleXMLRPCServer import SimpleXMLRPCServer
import requests
import socket
from clouds.openstack import processPack,stringMatch
from clouds.disk_scan import wipe,disk_encryption,get_diskpath
from clouds.vnc_spice_encry import VNC,spice
from clouds.loophole_scan import kvm,openstack,libvirt,qemu
from clouds.vdisk import vdisk
###########################
#ip和port配置信息
server_port=8000
server_ip = '127.0.0.1'
client_ip='127.0.0.1'
client_port=5000
###########################
#print localIP

server = SimpleXMLRPCServer((server_ip,server_port))
print "Listening on port",server_port
api='http://%s:%s/common/register' % (client_ip,str(client_port))
running=False
try:
    response = requests.post(api, data = {'ip':server_ip,'port':server_port})
    if response.status_code==200:
        '''
        注册自己的函数
        '''
        server.register_function(processPack, "processPack")
        server.register_function(stringMatch, "stringMatch")
        server.register_function(kvm, "kvm")
        server.register_function(libvirt, "libvirt")
        server.register_function(qemu, "qemu")
        server.register_function(openstack, "openstack")
        server.register_function(wipe, "wipe")
        server.register_function(disk_encryption, "disk_encryption")
        server.register_function(get_diskpath, "get_diskpath")
        server.register_function(VNC, "VNC")
        server.register_function(spice, "spice")
        server.register_function(vdisk, 'vdisk')
        
        server.serve_forever()
    else:
        print response.status_code
except BaseException,e:
    print e
finally:
    if not running:
        print 'server failed to start!'

